<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>zungbr.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="ZUNGBR.1"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a>( VECT, M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      CHARACTER          VECT
      INTEGER            INFO, K, LDA, LWORK, M, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="ZUNGBR.18"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a> generates one of the complex unitary matrices Q or P**H
</span><span class="comment">*</span><span class="comment">  determined by <a name="ZGEBRD.19"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a> when reducing a complex matrix A to bidiagonal
</span><span class="comment">*</span><span class="comment">  form: A = Q * B * P**H.  Q and P**H are defined as products of
</span><span class="comment">*</span><span class="comment">  elementary reflectors H(i) or G(i) respectively.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q
</span><span class="comment">*</span><span class="comment">  is of order M:
</span><span class="comment">*</span><span class="comment">  if m &gt;= k, Q = H(1) H(2) . . . H(k) and <a name="ZUNGBR.25"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a> returns the first n
</span><span class="comment">*</span><span class="comment">  columns of Q, where m &gt;= n &gt;= k;
</span><span class="comment">*</span><span class="comment">  if m &lt; k, Q = H(1) H(2) . . . H(m-1) and <a name="ZUNGBR.27"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a> returns Q as an
</span><span class="comment">*</span><span class="comment">  M-by-M matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**H
</span><span class="comment">*</span><span class="comment">  is of order N:
</span><span class="comment">*</span><span class="comment">  if k &lt; n, P**H = G(k) . . . G(2) G(1) and <a name="ZUNGBR.32"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a> returns the first m
</span><span class="comment">*</span><span class="comment">  rows of P**H, where n &gt;= m &gt;= k;
</span><span class="comment">*</span><span class="comment">  if k &gt;= n, P**H = G(n-1) . . . G(2) G(1) and <a name="ZUNGBR.34"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a> returns P**H as
</span><span class="comment">*</span><span class="comment">  an N-by-N matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  VECT    (input) CHARACTER*1
</span><span class="comment">*</span><span class="comment">          Specifies whether the matrix Q or the matrix P**H is
</span><span class="comment">*</span><span class="comment">          required, as defined in the transformation applied by <a name="ZGEBRD.42"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a>:
</span><span class="comment">*</span><span class="comment">          = 'Q':  generate Q;
</span><span class="comment">*</span><span class="comment">          = 'P':  generate P**H.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  M       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows of the matrix Q or P**H to be returned.
</span><span class="comment">*</span><span class="comment">          M &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of columns of the matrix Q or P**H to be returned.
</span><span class="comment">*</span><span class="comment">          N &gt;= 0.
</span><span class="comment">*</span><span class="comment">          If VECT = 'Q', M &gt;= N &gt;= min(M,K);
</span><span class="comment">*</span><span class="comment">          if VECT = 'P', N &gt;= M &gt;= min(N,K).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  K       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          If VECT = 'Q', the number of columns in the original M-by-K
</span><span class="comment">*</span><span class="comment">          matrix reduced by <a name="ZGEBRD.58"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a>.
</span><span class="comment">*</span><span class="comment">          If VECT = 'P', the number of rows in the original K-by-N
</span><span class="comment">*</span><span class="comment">          matrix reduced by <a name="ZGEBRD.60"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a>.
</span><span class="comment">*</span><span class="comment">          K &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the vectors which define the elementary reflectors,
</span><span class="comment">*</span><span class="comment">          as returned by <a name="ZGEBRD.65"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a>.
</span><span class="comment">*</span><span class="comment">          On exit, the M-by-N matrix Q or P**H.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A. LDA &gt;= M.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAU     (input) COMPLEX*16 array, dimension
</span><span class="comment">*</span><span class="comment">                                (min(M,K)) if VECT = 'Q'
</span><span class="comment">*</span><span class="comment">                                (min(N,K)) if VECT = 'P'
</span><span class="comment">*</span><span class="comment">          TAU(i) must contain the scalar factor of the elementary
</span><span class="comment">*</span><span class="comment">          reflector H(i) or G(i), which determines Q or P**H, as
</span><span class="comment">*</span><span class="comment">          returned by <a name="ZGEBRD.76"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a> in its array argument TAUQ or TAUP.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
</span><span class="comment">*</span><span class="comment">          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The dimension of the array WORK. LWORK &gt;= max(1,min(M,N)).
</span><span class="comment">*</span><span class="comment">          For optimum performance LWORK &gt;= min(M,N)*NB, where NB
</span><span class="comment">*</span><span class="comment">          is the optimal blocksize.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          If LWORK = -1, then a workspace query is assumed; the routine
</span><span class="comment">*</span><span class="comment">          only calculates the optimal size of the WORK array, returns
</span><span class="comment">*</span><span class="comment">          this value as the first entry of the WORK array, and no error
</span><span class="comment">*</span><span class="comment">          message related to LWORK is issued by <a name="XERBLA.89"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX*16         ZERO, ONE
      PARAMETER          ( ZERO = ( 0.0D+0, 0.0D+0 ),
     $                   ONE = ( 1.0D+0, 0.0D+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY, WANTQ
      INTEGER            I, IINFO, J, LWKOPT, MN, NB
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      LOGICAL            <a name="LSAME.107"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
      INTEGER            <a name="ILAENV.108"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="LSAME.109"></a><a href="lsame.f.html#LSAME.1">LSAME</a>, <a name="ILAENV.109"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="XERBLA.112"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>, <a name="ZUNGLQ.112"></a><a href="zunglq.f.html#ZUNGLQ.1">ZUNGLQ</a>, <a name="ZUNGQR.112"></a><a href="zungqr.f.html#ZUNGQR.1">ZUNGQR</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input arguments
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      WANTQ = <a name="LSAME.122"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( VECT, <span class="string">'Q'</span> )
      MN = MIN( M, N )
      LQUERY = ( LWORK.EQ.-1 )
      IF( .NOT.WANTQ .AND. .NOT.<a name="LSAME.125"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( VECT, <span class="string">'P'</span> ) ) THEN
         INFO = -1
      ELSE IF( M.LT.0 ) THEN
         INFO = -2
      ELSE IF( N.LT.0 .OR. ( WANTQ .AND. ( N.GT.M .OR. N.LT.MIN( M,
     $         K ) ) ) .OR. ( .NOT.WANTQ .AND. ( M.GT.N .OR. M.LT.
     $         MIN( N, K ) ) ) ) THEN
         INFO = -3
      ELSE IF( K.LT.0 ) THEN
         INFO = -4
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -6
      ELSE IF( LWORK.LT.MAX( 1, MN ) .AND. .NOT.LQUERY ) THEN
         INFO = -9
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
         IF( WANTQ ) THEN
            NB = <a name="ILAENV.143"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="ZUNGQR.143"></a><a href="zungqr.f.html#ZUNGQR.1">ZUNGQR</a>'</span>, <span class="string">' '</span>, M, N, K, -1 )
         ELSE
            NB = <a name="ILAENV.145"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="ZUNGLQ.145"></a><a href="zunglq.f.html#ZUNGLQ.1">ZUNGLQ</a>'</span>, <span class="string">' '</span>, M, N, K, -1 )
         END IF
         LWKOPT = MAX( 1, MN )*NB
         WORK( 1 ) = LWKOPT
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.152"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="ZUNGBR.152"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( M.EQ.0 .OR. N.EQ.0 ) THEN
         WORK( 1 ) = 1
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( WANTQ ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Form Q, determined by a call to <a name="ZGEBRD.167"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a> to reduce an m-by-k
</span><span class="comment">*</span><span class="comment">        matrix
</span><span class="comment">*</span><span class="comment">
</span>         IF( M.GE.K ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           If m &gt;= k, assume m &gt;= n &gt;= k
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="ZUNGQR.174"></a><a href="zungqr.f.html#ZUNGQR.1">ZUNGQR</a>( M, N, K, A, LDA, TAU, WORK, LWORK, IINFO )
<span class="comment">*</span><span class="comment">
</span>         ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           If m &lt; k, assume m = n
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Shift the vectors which define the elementary reflectors one
</span><span class="comment">*</span><span class="comment">           column to the right, and set the first row and column of Q
</span><span class="comment">*</span><span class="comment">           to those of the unit matrix
</span><span class="comment">*</span><span class="comment">
</span>            DO 20 J = M, 2, -1
               A( 1, J ) = ZERO
               DO 10 I = J + 1, M
                  A( I, J ) = A( I, J-1 )
   10          CONTINUE
   20       CONTINUE
            A( 1, 1 ) = ONE
            DO 30 I = 2, M
               A( I, 1 ) = ZERO
   30       CONTINUE
            IF( M.GT.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Form Q(2:m,2:m)
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="ZUNGQR.198"></a><a href="zungqr.f.html#ZUNGQR.1">ZUNGQR</a>( M-1, M-1, M-1, A( 2, 2 ), LDA, TAU, WORK,
     $                      LWORK, IINFO )
            END IF
         END IF
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Form P', determined by a call to <a name="ZGEBRD.204"></a><a href="zgebrd.f.html#ZGEBRD.1">ZGEBRD</a> to reduce a k-by-n
</span><span class="comment">*</span><span class="comment">        matrix
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.LT.N ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           If k &lt; n, assume k &lt;= m &lt;= n
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="ZUNGLQ.211"></a><a href="zunglq.f.html#ZUNGLQ.1">ZUNGLQ</a>( M, N, K, A, LDA, TAU, WORK, LWORK, IINFO )
<span class="comment">*</span><span class="comment">
</span>         ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           If k &gt;= n, assume m = n
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Shift the vectors which define the elementary reflectors one
</span><span class="comment">*</span><span class="comment">           row downward, and set the first row and column of P' to
</span><span class="comment">*</span><span class="comment">           those of the unit matrix
</span><span class="comment">*</span><span class="comment">
</span>            A( 1, 1 ) = ONE
            DO 40 I = 2, N
               A( I, 1 ) = ZERO
   40       CONTINUE
            DO 60 J = 2, N
               DO 50 I = J - 1, 2, -1
                  A( I, J ) = A( I-1, J )
   50          CONTINUE
               A( 1, J ) = ZERO
   60       CONTINUE
            IF( N.GT.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Form P'(2:n,2:n)
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="ZUNGLQ.235"></a><a href="zunglq.f.html#ZUNGLQ.1">ZUNGLQ</a>( N-1, N-1, N-1, A( 2, 2 ), LDA, TAU, WORK,
     $                      LWORK, IINFO )
            END IF
         END IF
      END IF
      WORK( 1 ) = LWKOPT
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="ZUNGBR.243"></a><a href="zungbr.f.html#ZUNGBR.1">ZUNGBR</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
